package com.shd.edanpei.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseFragment;
import com.shd.edanpei.presenter.contract.PublishContract;
import com.shd.edanpei.enums.OrderTypeEnum;
import com.shd.edanpei.presenter.PublishPresenter;
import com.shd.edanpei.ui.adapter.ProductNewAdapter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mc on 2018/10/17.
 * yang-wen-wen
 */

public class PublishFragment extends BaseFragment<PublishPresenter> implements PublishContract.PublishIView {


    @BindView(R.id.radio_group)
    RadioGroup radioGroup;
    @BindView(R.id.image)
    ImageView image;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.iv_location)
    ImageView ivLocation;

    private int publishType;//1：住房订单   2：车辆订单 3:个人信用  4：企业税金


    @Override
    protected Object setLayout() {
        return R.layout.fragment_publish;
    }

    @Override
    protected PublishPresenter bindPresenter() {
        return new PublishPresenter(this);
    }

    @Override
    protected void initView(@Nullable View view, @Nullable Bundle savedInstanceState) {

        publishType = OrderTypeEnum.house.getKey();
        initLayout(R.id.radio_button1);
    }

    @Override
    protected void initListener() {
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                initLayout(checkedId);
            }
        });
    }

    @OnClick(R.id.tv_address)
    void onAddress() {
        mPresenter.onAddress();
    }

    @OnClick(R.id.tv_create)
    void onCreate() {
        mPresenter.onCreate(publishType);
    }


    private void initLayout(int id) {
        switch (id) {
            case R.id.radio_button1:
                //住房订单
                publishType = OrderTypeEnum.house.getKey();
                image.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.pic_house));
                break;
            case R.id.radio_button2:
                //车辆订单
                publishType = OrderTypeEnum.car.getKey();
                image.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.pic_car));
                break;
                //个人贷款
            case R.id.radio_button3:
                publishType=OrderTypeEnum.personal.getKey();
                image.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.geren));
                break;
                //企业税金
            case R.id.radio_button4:
                publishType=OrderTypeEnum.enterprise.getKey();
                image.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.qiyeshuiijin));
                break;
            default:
                break;
        }
    }

    @Override
    public void setAddress(String str) {
        tvAddress.setText(str);
        tvAddress.setTextColor(getResources().getColor(R.color.black));
        ivLocation.setImageDrawable(getResources().getDrawable(R.drawable.ic_unaddress_small2));
    }

    @Override
    public ProductNewAdapter getAdpster() {
        return null;
    }
}
